const CompressionPlugin = require('compression-webpack-plugin')
let webpack = require('webpack')
const isProd = process.env.NODE_ENV === "production"


const loadPlugin = () => {
    const plugins = [
        new webpack.ProvidePlugin({
            jQuery: "jquery",
            $: "jquery"
        })
    ]
    isProd && plugins.push(
        new CompressionPlugin({
            test: /\.(js|css|html|png|jpg|svg)?$/i,     // 压缩文件格式
            filename: '[path].gz[query]',   // 压缩后的文件名
            algorithm: 'gzip',              // 使用gzip压缩
            minRatio: 0.8                   // 压缩率小于1才会压缩
        })
    )
    return plugins
}

module.exports = loadPlugin


